'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	let count = await db.collection("user").where({
		openid:event.openid
	}).count()
	console.log(count);
	if(count.total==0){
		return await db.collection("user").add({
			 name:event.name,
			 create_time:Date.now(),
			 type:'wx',
			 openid:event.openid
		 })
	}else{
		return await db.collection("user").where({openid:event.openid}).update({name:event.name})
	}
};
